<?php


class HeadlineTable extends Doctrine_Table
{
  public static function getInstance()
  {
    return Doctrine_Core::getTable('Headline');
  }
  
  public function getBackendListQuery(Doctrine_Query $query)
  {
    $rootAlias = $query->getRootAlias();
    
    $user = sfContext::getInstance()->getUser();
    
    if (!$user->hasCredential('super'))
    {
      $query->andWhereIn('area_id', $user->getAreaIds());
    }
    
    return $query->innerJoin("$rootAlias.area a");
  }
  
  public function getBackendHeadline2FormListQuery()
  {
    $query = $this->createQuery('h');
    
    $user = sfContext::getInstance()->getUser();
    
    if (!$user->hasCredential('super'))
    {
      $query->andWhereIn('area_id', $user->getAreaIds());
    }
    
    return $query;
  }
}